package com.timoon.sample.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.timoon.sample.dao.ProductDAO;
import com.timoon.sample.dao.model.Product;
import com.timoon.sample.dao.model.ProductExample;
import com.timoon.webcomponent.utility.product.discount.Discount1Service;

/**
 *<p></p>
 *<p></p>
 *<p>Copyright:Copyright(c)2013.4.1</p>
 *<p>Company:timoon</p>
 *@author 付乐天
 *@version 1.0 */

@Service(value="com.timoon.sample.service.DiscountServiceImpl")
public class DiscountServiceImpl implements Discount1Service {

	@Resource
	private ProductDAO productDAOImpl;
	
	@Override
	public Product getProductByType(final int type) {
		// TODO Auto-generated method stub
		
		@SuppressWarnings("unchecked")
		List<Product> products=this.productDAOImpl.selectByExample(new ProductExample(){{
			this.createCriteria().andStatusNotEqualTo(0).andTypeEqualTo(type);
		}});
		
		if(products!=null&&products.size()>0){
			return products.get(0);
		}else{
			return null;
		}
	}

	public ProductDAO getProductDAOImpl() {
		return productDAOImpl;
	}

	public void setProductDAOImpl(ProductDAO productDAOImpl) {
		this.productDAOImpl = productDAOImpl;
	}

}
